CXX = g++
CFLAGS = -O2 -Wall -Iinclude/ -I/usr/local/papi-3.6.1/include
LDFLAGS = -Llib/ -lgmpxx -lgmp -L/usr/local/papi-3.6.1/lib/ -lpapi
SRC_DIR = src
BIN_DIR = bin
ADD_SRC = $(SRC_DIR)/add.cpp 
MUL_SRC = $(SRC_DIR)/mul.cpp 
TMUL_SRC = $(SRC_DIR)/tmul.cpp $(SRC_DIR)/generator.cpp
ADD_TARGET = $(BIN_DIR)/add
MUL_TARGET = $(BIN_DIR)/mul
TMUL_TARGET = $(BIN_DIR)/tmul
export LD_LIBRARY_PATH=lib/:/usr/local/papi-3.6.1/lib/

all: add mul tmul tex

compile:
	$(CXX) $(CFLAGS) $(ADD_SRC) -o $(ADD_TARGET) $(LDFLAGS)
	$(CXX) $(CFLAGS) $(MUL_SRC) -o $(MUL_TARGET) $(LDFLAGS)
	$(CXX) $(CFLAGS) $(TMUL_SRC) -o $(TMUL_TARGET) $(LDFLAGS)

tex:
	cd doc/ && make -f Makefile

add:
	$(CXX) $(CFLAGS) $(ADD_SRC) -o $(ADD_TARGET) $(LDFLAGS)
	@echo "Running integer addition tests\n"
	$(ADD_TARGET) -i > $(BIN_DIR)/integer_add.dat
	gnuplot < $(SRC_DIR)/add.plt

mul:
	$(CXX) $(CFLAGS) $(MUL_SRC) -o $(MUL_TARGET) $(LDFLAGS)
	@echo "Running large integer multiplications tests\n"
	$(MUL_TARGET) -i > $(BIN_DIR)/integer_mul.dat 
	gnuplot < $(SRC_DIR)/mul.plt

tmul:
	$(CXX) $(CFLAGS) $(TMUL_SRC) -o $(TMUL_TARGET) $(LDFLAGS)
	@echo "Running threshold integer multiplications tests\n"
	$(TMUL_TARGET) -k > $(BIN_DIR)/integer_tmul_karatsuba.dat 
	gnuplot < $(SRC_DIR)/tmul_karatsuba.plt
	$(TMUL_TARGET) -t > $(BIN_DIR)/integer_tmul_toom3.dat 
	gnuplot < $(SRC_DIR)/tmul_toom3.plt
	$(TMUL_TARGET) -f > $(BIN_DIR)/integer_tmul_fft.dat 
	gnuplot < $(SRC_DIR)/tmul_fft.plt

clean:
	@rm -rfv $(ADD_TARGET) $(MUL_TARGET) $(TMUL_TARGET)
	cd doc/ && make -f Makefile clean
